package leetcode_数组.统计数组中的元素;

import java.util.Arrays;

// 错误的集合
public class _645 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(findErrorNums(new int[]{1, 2, 2, 4})));
    }

    public static int[] findErrorNums(int[] nums) {
        int[] a = new int[nums.length + 1];
        int[] ans = new int[2];
        for (int num : nums) {
            a[num]++;
        }
        for (int i = 1; i < a.length; i++) {
            if (a[i] > 1) {
                ans[0] = i;
            }
            if (a[i] == 0) {
                ans[1] = i;
            }
        }
        return ans;
    }

}
